﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Data.Entity.Infrastructure;
using EntityModel;

namespace OA.DataBase
{
    public class OAContext : DbContext
    {
        private readonly static string CONNECTION_STRING = "OAContext";

        public DbSet<User> Users { get; set; }
        public DbSet<Module> Modules { get; set; }
        public DbSet<SysAction> SysActions { get; set; }
        public DbSet<Employee> Employees { get; set; }

        public OAContext()
            : base(CONNECTION_STRING)//不写这个  默认的就是SchoolContext    
        {
            this.Configuration.ProxyCreationEnabled = false;
        }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();//移除复数表名的契约
            modelBuilder.Entity<Module>().
                HasMany(m => m.SysActions).
                WithMany(sysm => sysm.Modules).
                Map(m => m.MapLeftKey("ModuleID").MapRightKey("SysActionID").ToTable("Module_SysAction"));
        }
    }
}
